<template>
  <div v-loading="loading" class="allView">
    <div class="header">
      <div class="icon" />
      <div class="title">全网概览</div>
    </div>
    <div class="body">
      <div class="dataCard">
        <div class="flex">
          <div class="icon">
            <img class="icon" src="../../assets/overview/node_count.png" alt="">
          </div>
          <div class="info">
            <div class="count">{{ data.nodeCount }}</div>
            <div class="remark">{{ '节点个数' }}</div>
          </div>
        </div>
      </div>
      <div class="dataCard">
        <div class="flex">
          <div class="icon">
            <img class="icon" style="width: 38px;" src="../../assets/overview/contract_count.png" alt="">
          </div>
          <div class="info">
            <div class="count">{{ data.contractCount }}</div>
            <div class="remark">{{ '已部署智能合约' }}</div>
          </div>
        </div>
      </div>
      <div class="dataCard">
        <div class="flex">
          <div class="icon">
            <img class="icon" src="../../assets/overview/block_count.png" alt="">
          </div>
          <div class="info">
            <div class="count">{{ data.latestBlock }}</div>
            <div class="remark">{{ '区块数量' }}</div>
          </div>
        </div>
      </div>
      <div class="dataCard">
        <div class="flex">
          <div class="icon">
            <img class="icon" src="../../assets/overview/trade_count.png" alt="">
          </div>
          <div class="info">
            <div class="count">{{ data.transactionCount }}</div>
            <div class="remark">{{ '交易数量' }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getNetworkStatistics } from '@/api/overview'
export default {
  name: 'AllView',
  components: { },
  props: {
    canShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      data: {},
      loading: true
    }
  },
  watch: {
    canShow(n, o) {
      if (n) {
        this.loadData()
      }
    }
  },
  mounted() {
    if (this.canShow) {
      this.loadData()
    }
  },
  methods: {
    async loadData() {
      try {
        this.loading = true
        const { code, data } = await getNetworkStatistics(1)
        if (!code) {
          this.data = data
        }
      } catch (error) {
        console.error(error)
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.allView {
	width: 500px;
	height: 324px;
  margin: 15px;
  padding: 0 20px;
	background: #FFFFFF;
	box-shadow: 0px 6px 25px 0px rgba(0, 0, 0, 0.04);
	border-radius: 10px;
  display: inline-block;
  vertical-align: top;
	.header {
		height: 64px;
    display: flex;
    align-items: center;
    .title {
      font-size: 18px;
      font-family: SourceHanSansCN-Medium, SourceHanSansCN;
      font-weight: 500;
      color: #2C2C2C;
    }
    .icon {
      width: 24px;
      height: 24px;
      background: url('../../assets/overview/view.png');
      background-size: 100%;
      margin-right: 20px;
    }
	}
  .body {
    .dataCard {
      width: 220px;
      height: 110px;
      background: #FFFFFF;
      border-radius: 4px;
      border: 1px solid #F2F2F2;
      display: inline-block;
      padding: 30px 20px;
      &:nth-child(odd){
        margin-right: 20px;
        margin-top: 20px;
      }
      &:first-child {
        margin-top: 0;
      }
      &:hover {
        box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.08);
      }
      .icon{
        width: 48px;
        height: 48px;
      }
      .info{
        width: 100%;
        margin-left: 10px;
        text-align: center;
        .count {
          // width: 14px;
          height: 24px;
          font-size: 24px;
          font-family: SourceHanSansCN-Medium, SourceHanSansCN;
          font-weight: 500;
          color: #2C2C2C;
          line-height: 24px;
        }
        .remark {
          height: 12px;
          font-size: 12px;
          font-family: SourceHanSansCN-Regular, SourceHanSansCN;
          font-weight: 400;
          color: #666666;
          line-height: 12px;
          margin-top: 10px;
        }
      }
    }
  }
}

.flex {
  display: flex;
  align-items: center;
}
</style>
